home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / Python / pdapilot.py < prev    next >
Text File  |  1997-08-09  |  4KB  |  203 lines

  1. import _pdapilot
  2. from _pdapilot import *
  3.  
  4. class Block:
  5.     def __init__(self, contents=None, dlpdb=None):
  6.         if contents != None:
  7.             self.unpack(contents, dlpdb)
  8.         else:
  9.             self.fill()
  10.  
  11.     def __repr__(self):
  12.         return '<' + self.__class__.__name__ +' instance, '+ repr(self.__dict__) + '>'
  13.  
  14.     def pack(self, dlpdb=None):
  15.         return self.raw
  16.  
  17.     def unpack(self, block, dlpdb=None):
  18.         self.raw = block
  19.  
  20.     def fill(self):
  21.         0
  22.  
  23. class PrefBlock (Block):
  24.     def __init__(self, contents=None, dlp=None, creator=None, id=None, version=None, backup=None):
  25.         if creator != None:
  26.             self.creator = creator
  27.         if id != None:
  28.             self.id = id
  29.         if version != None:
  30.             self.version = version
  31.         if backup != None:
  32.             self.backup = backup
  33.         if contents != None:
  34.             self.unpack(contents, dlp)
  35.         else:
  36.             self.fill()
  37.  
  38. class ResourceBlock (Block):
  39.     def __init__(self, contents=None, dlpdb=None, type=None, id=None):
  40.         if type != None:
  41.             self.type = type
  42.         if id != None:
  43.             self.id = id
  44.         if contents != None:
  45.             self.unpack(contents, dlpdb)
  46.         else:
  47.             self.fill()
  48.  
  49. class RecordBlock (Block):
  50.     def __init__(self, contents=None, dlpdb=None, index=None, id=None, attr=None, category=None):
  51.         if index != None:
  52.             self.index = index
  53.         if id != None:
  54.             self.id = id
  55.         if attr != None:
  56.             if attr & 0x80:
  57.                 self.deleted = 1
  58.             else:
  59.                 self.deleted = 0
  60.             if attr & 0x40:
  61.                 self.modified = 1
  62.             else:
  63.                 self.mofified = 0
  64.             if attr & 0x20:
  65.                 self.busy = 1
  66.             else:
  67.                 self.busy = 0
  68.             if attr & 0x10:
  69.                 self.secret = 1
  70.             else:
  71.                 self.secret = 0
  72.             if attr & 0x08:
  73.                 self.archived = 1
  74.             else:
  75.                 self.archived = 0
  76.         if category != None:
  77.             self.category = category
  78.         if contents != None:
  79.             self.unpack(contents, dlpdb)
  80.         else:
  81.             self.fill()
  82.     def fill(self):
  83.         self.deleted = 0
  84.         self.modified = 0
  85.         self.busy = 0
  86.         self.secret = 0
  87.         self.archived = 0
  88.  
  89. class AppBlock (Block):
  90.     """ AppBlock is intended to keep any methods common to most app blocks
  91.     such as category manipulation routines, etc.
  92.     """
  93.  
  94. class RecordDatabase:
  95.     Record = RecordBlock
  96.     AppBlock = Block
  97.     SortBlock = Block
  98.     Pref = PrefBlock
  99.  
  100. class ResourceDatabase:
  101.     Resource = ResourceBlock
  102.     AppBlock = Block
  103.     SortBlock = Block
  104.     Pref = PrefBlock
  105.  
  106. class Database:
  107.     Resource = ResourceBlock
  108.     Record = RecordBlock
  109.     AppBlock = Block
  110.     SortBlock = Block
  111.     Pref = PrefBlock
  112.  
  113. class Memo (RecordDatabase):
  114.     creator = 'memo'
  115.     name = 'MemoDB'
  116.     class Record (RecordBlock):
  117.         def fill(self):
  118.             self.text = ''
  119.             RecordBlock.fill(self)
  120.         
  121.         def pack(self, dlpdb=None):
  122.             self.raw = _pdapilot.MemoPack(self.__dict__)
  123.             return self.raw
  124.         
  125.         def unpack(self, block, dlpdb=None):
  126.             self.raw = block
  127.             _pdapilot.MemoUnpack(self.__dict__, block)
  128.             
  129.     class AppBlock (AppBlock):
  130.         def pack(self, dlpdb=None):
  131.             self.raw = _pdapilot.MemoPackAppBlock(self.__dict__)
  132.             return self.raw
  133.         
  134.         def unpack(self, block, dlpdb=None):
  135.             self.raw = block
  136.             _pdapilot.MemoUnpackAppBlock(self.__dict__, block)
  137.  
  138. class ToDo (RecordDatabase):
  139.     creator = 'todo'
  140.     name = 'ToDoDB'
  141.     class Record (RecordBlock):
  142.         def fill(self):
  143.             self.indefinite = 0
  144.             self.priority = 0
  145.             self.complete = 0
  146.             self.note = None
  147.             self.description = None
  148.             self.due = None
  149.             RecordBlock.fill(self)
  150.         
  151.         def pack(self, dlpdb=None):
  152.             self.raw = _pdapilot.ToDoPack(self.__dict__)
  153.             return self.raw
  154.         
  155.         def unpack(self, block, dlpdb=None):
  156.             self.raw = block
  157.             _pdapilot.ToDoUnpack(self.__dict__, block)
  158.             
  159.     class AppBlock (AppBlock):
  160.         def pack(self, dlpdb=None):
  161.             self.raw = _pdapilot.ToDoPackAppBlock(self.__dict__)
  162.             return self.raw
  163.         
  164.         def unpack(self, block, dlpdb=None):
  165.             self.raw = block
  166.             _pdapilot.ToDoUnpackAppBlock(self.__dict__, block)
  167.  
  168.  
  169.  
  170. class Mail (RecordDatabase):
  171.     creator = 'mail'
  172.     name = 'MailDB'
  173.     class Pref (PrefBlock):
  174.         def fill(self):
  175.             if (self.id == 1) or (self.id == 2):
  176.                 self.syncType = None;
  177.                 self.getHigh = None;
  178.                 self.getContaining = None;
  179.                 self.truncate = None;
  180.                 self.filterTo = None;
  181.                 self.filterFrom = None;
  182.                 self.filterSubject = None;
  183.             elif self.id == 3:
  184.                 self.signature = None;
  185.             
  186.         def pack(self, dlp=None):
  187.             self.raw = _pdapilot.MailPackPref(self.__dict__, self.id)
  188.             return self.raw
  189.         
  190.         def unpack(self, block, dlp=None):
  191.             self.raw = block
  192.             _pdapilot.MailUnpackPref(self.__dict__, block, self.id)
  193.  
  194. DBClasses[''] = Database
  195. PrefClasses[''] = PrefBlock
  196.  
  197. DBClasses[Memo.name] = Memo
  198. DBClasses[ToDo.name] = ToDo
  199. DBClasses[Mail.name] = Mail
  200. PrefClasses[Mail.creator] = {'': Mail.Pref}
  201.  
  202.  
  203.